package com.drcoffee.drcoffeemall.controller;

import com.drcoffee.drcoffeemall.entry.InvoiceRecords;
import com.drcoffee.drcoffeemall.entry.PayVoucher;
import com.drcoffee.drcoffeemall.entry.Result;
import com.drcoffee.drcoffeemall.entry.search.OrderSearch;
import com.drcoffee.drcoffeemall.service.OrderService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OrderController {

    final
    OrderService orderService;

    public OrderController(OrderService orderService) {
        this.orderService = orderService;
    }

    /*
     * 查询用户所有订单
     * */
    @PostMapping("/getAllOrder")
    public Result getAllOrder(@RequestBody OrderSearch orderSearch) {
        return orderService.getAllOrder(orderSearch);
    }



    /*
     * 提交订单
     * */
    @PostMapping("/submitOrder")
    public Result submitOrder(@RequestHeader String Token, @RequestBody Map<String, Object> orderMap) {
//        System.out.println(order);
        return orderService.submitOrder(Token, orderMap);
    }

    /*
     * 发送订单至邮箱
     * */
    @GetMapping("sendOrderEmail")
    public Map<String, Object> sendOrderEmail(HttpServletResponse response, @RequestHeader String Token, @RequestParam String order_code) {
        return orderService.sendOrderEmail(response, Token, order_code);
    }

    @GetMapping(value = "/derivePdf", name = "导出PDF")
    public File derivePdf(HttpServletResponse response, String order_code, String language, Integer type) throws Exception {
        return orderService.derivePdf(response, order_code, language, type);
    }


    /*
     * 查询物流信息
     * */
    @GetMapping("/getTransport")
    public Result getTransport(@RequestParam String order_code) {
        Result resultMap = orderService.getTransport(order_code);
        return orderService.getTransport(order_code);
    }


    /*
     * 根据code查询订单
     * */
    @GetMapping("getOrderByCode")
    public Result getOrderByCode(@RequestHeader String Token, @RequestParam String code, @RequestParam String language) {
        return orderService.getOrderByCode(Token, code, language);
    }

    /*
     * 根据code查询订单金额
     * */
    @GetMapping("getNoPayOrderByCode")
    public Result getNoPayOrderByCode(@RequestParam String code) {
        return orderService.getNoPayOrderByCode(code);
    }

    /*
     * 设置付款方式为转账
     * */
    @GetMapping("setOrderBackStatus")
    public Result setOrderBackStatus(@RequestParam String code) {
        return orderService.setOrderBackStatus(code);
    }

    /*
     * 根据code查询订单单头
     * */
    @GetMapping("getOrderHeader")
    public Result getOrderHeader(@RequestParam String code) {
        return orderService.getOrderHeader(code);
    }


    /*
     * 添加凭证记录
     * */
    @PostMapping("/addPayVoucher")
    public Result addPayVoucher(@RequestBody PayVoucher payVoucher) {
        return orderService.addPayVoucher(payVoucher);
    }


    /*
     * 发送汇款短信
     * */
    @GetMapping("/sendRemit")
    public Result sendRemit(@RequestParam String phone, @RequestParam String code) {
        return orderService.sendRemit(phone, code);
    }

    /*
     * 查询汇款凭证
     * */
    @GetMapping("/getPayVoucher")
    public Result getPayVoucher(@RequestParam String code) {
        return orderService.getPayVoucher(code);
    }


    /*
     * 查询订单配件合计金额
     * */
    @PostMapping("/getOrderPartsTotal")
    public Result getOrderPartsTotal(@RequestBody Map<String, Object> par) {
        return orderService.getOrderPartsTotal(par);
    }

    /*
     * 查询订单支付方式
     * */
    @GetMapping("/getPayType")
    public Result getPayType(@RequestParam String code) {
        return orderService.getPayType(code);
    }

    /*
     * 取消订单
     * */
    @GetMapping("/cancelOrder")
    public Result cancelOrder(@RequestParam String code) {
        return orderService.cancelOrder(code);
    }


    /*
     * 支付校验
     * */
    @GetMapping("/allPayVerify")
    public Result allPayVerify(@RequestParam String order_code, @RequestParam Integer type) {
        return orderService.allPayVerify(order_code, type);
    }


    @GetMapping("/setOrderStatus")
    public Result setOrderStatus(@RequestParam String order_code, @RequestParam Integer status) {
        return orderService.setOrderStatus(order_code, status);
    }


}
